package controleur;

/*
 * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *   - Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *
 *   - Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in the
 *     documentation and/or other materials provided with the distribution.
 *
 *   - Neither the name of Oracle or the names of its
 *     contributors may be used to endorse or promote products derived
 *     from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

import java.awt.*;
import java.awt.event.*;
import java.awt.geom.AffineTransform;
import java.awt.image.*;
import java.io.*;

import javax.imageio.*;
import javax.imageio.stream.ImageOutputStream;
import javax.swing.*;

/**
 * This class demonstrates how to load an Image from an external file
 */
public class ThumbFactory {
	
//	File fic ;
//	BufferedImage bi ;
//	BufferedImage thumb ;

//	public static void main(String[] args) {
//		String path = "Z:/GG_ENM_ElevesTSE_2010-2012/laurent.sohier/projet_application/";
//		BufferedImage img = null;
//		try {
//			img = ImageIO.read(new File(path + "photo.jpg"));
//			System.out.println("Lecture image");
//		} catch (IOException e) {
//		}
////		double ratio = 0.35 ;
////		int w = (int) (ratio * img.getWidth()) ;
////		int h = (int) (ratio * img.getHeight()) ;
////		BufferedImage thumb = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB) ;
////		Graphics2D g2d = thumb.createGraphics() ;
////		AffineTransform at = AffineTransform.getScaleInstance(ratio,ratio) ;
////		g2d.drawRenderedImage(img, at) ;
////		g2d.dispose() ;
//		File output = new File(path + "essai.jpg") ;
//		BufferedImage bi = this.create(img, 0.5) ;
//		try {
//			ImageIO.write(bi, "jpg", output) ;
//		} catch (IOException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//	}
	
//	public ThumbGenerator(File f, double ratio) throws IOException {
//		fic = f ;
//		ImageIO.read(fic) ;
//		thumb = this.create(bi, ratio) ;
//	}
//	
//	public void ecrit(File f) {
//		
//	}
	
	
	
	public static BufferedImage scale(BufferedImage bi, double ratio) {
		BufferedImage im = new BufferedImage((int) (bi.getWidth()* ratio), (int) (bi.getHeight() * ratio) , bi.getType()) ;
		AffineTransform at = new AffineTransform() ;
		at.scale(ratio, ratio) ;
		AffineTransformOp ao = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR) ;
		return ao.filter(bi, im) ;
	}
}
